﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class UserRepository
    {
        StationeryInventoryEntities1 ent;

        public UserRepository()
        {
            ent = new StationeryInventoryEntities1();
        }

        #region Select Method

        public User GetUserByUsernameAndPassword(string username, string password)
        {
            User user = new User();

            var u = ent.Users.FirstOrDefault(x => x.UserName == username && x.Password == password);

            if (u != null)
            {
                user = u;
            }

            return user;
        }

        public User GetUserByUsername(string username)
        {
            User user = new User();

            var u = ent.Users.FirstOrDefault(x => x.UserName == username);

            if (u != null)
            {
                user = u;
            }
            return user;
        }

        public User GetUserByUserId(int userId)
        {
            User user = new User();

            var u = ent.Users.FirstOrDefault(x => x.UserID == userId);

            if (u != null)
            {
                user = u;
            }
            return user;
        }

        #endregion

    }
}
